/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.client.event;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.SimpleEventBus;
import java.util.ArrayList;
import java.util.List;
import org.lucava.lib.client.event.EventPlugin;

/**
 *
 * @author glenn
 */
public class EventDispatcher extends SimpleEventBus {

    private List<EventPlugin> plugins;

    public EventDispatcher() {
        super();
        this.plugins = new ArrayList<EventPlugin>();
    }

    @Override
    public void fireEvent(GwtEvent<?> event) {

        this.preFireEvent(event);
        super.fireEvent(event);
        this.postFireEvent(event);
    }

    public void addPlugin(EventPlugin plugin) {
        plugins.add(plugin);
    }

    public void preFireEvent(GwtEvent<?> event) {

        for (EventPlugin pl : plugins) {
            pl.preFireEvent(this, event);
        }

    }

    public void postFireEvent(GwtEvent<?> event) {

        for (EventPlugin pl : plugins) {
            pl.postFireEvent(this, event);
        }
    }
}
